package com.tanhua.admin.controller;

import com.tanhua.admin.service.MessagesService;
import com.tanhua.model.dto.MessageDto;
import com.tanhua.model.vo.MovementsVO;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Xiao
 * @version 1.0
 * @description 动态、评论管理接口
 * @date 2021/11/3
 */
@RestController
@RequestMapping("/manage/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    /**
     * 动态管理-动态分页
     *
     * @param messageDto pagesize、page、uid、state
     * @return
     */
    @GetMapping
    public ResponseEntity getMessages(MessageDto messageDto) {
        PageResult pageResult = messagesService.getMessages(messageDto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 动态管理-动态详情
     *
     * @param id 动态id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity getMessage(@PathVariable String id) {
        MovementsVO movementsVO = messagesService.getMessage(id);
        return ResponseEntity.ok(movementsVO);
    }

    /**
     * 评论管理-评论列表翻页
     *
     * @param page
     * @param pagesize
     * @param messageID 动态id
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity getComments(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,
                                      String messageID) {
        PageResult pageResult = messagesService.getComments(page, pagesize, messageID);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 动态管理-动态通过
     * @param ids   动态id列表
     * @return
     */
    @PostMapping("/pass")
    public ResponseEntity pass(@RequestBody String[] ids) {
        Integer state = 1;
        String message = messagesService.checkMessage(ids, state);
        Map<String, String> map = new HashMap<>();
        map.put("message", message);
        return ResponseEntity.ok(map);
    }

    /**
     * 动态管理-动态驳回
     * @param ids   动态id列表
     * @return
     */
    @PostMapping("/reject")
    public ResponseEntity reject(@RequestBody String[] ids) {
        Integer state = 2;
        String message = messagesService.checkMessage(ids, state);
        Map<String, String> map = new HashMap<>();
        map.put("message", message);
        return ResponseEntity.ok(map);
    }
}
